home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F47378_defaultss.xsl < prev    next >
Encoding:
Extensible Markup Language  |  1999-03-08  |  13.7 KB  |  313 lines

  1. <?xml version="1.0"?>
  2. <?xml-stylesheet type="text/xsl" href="defaultss.xsl"?>
  3. <!--
  4.   IE5 default style sheet, provides a view of any XML document
  5.   and provides the following features:
  6.   - auto-indenting of the display, expanding of entity references
  7.   - click or tab/return to expand/collapse
  8.   - color coding of markup
  9.   - color coding of recognized namespaces - xml, xmlns, xsl, dt
  10.   
  11.   This style sheet is available in IE5 in a compact form at the URL
  12.   "res://msxml.dll/DEFAULTSS.xsl".  This version differs only in the
  13.   addition of comments and whitespace for readability.
  14.   
  15.   Author:  Jonathan Marsh (jmarsh@microsoft.com)
  16. -->
  17.  
  18. <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"
  19.                 xmlns:dt="urn:schemas-microsoft-com:datatypes"
  20.                 xmlns:d2="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
  21.  
  22. <xsl:template match="/">
  23.   <HTML>
  24.     <HEAD>
  25.       <STYLE>
  26.         BODY {font:x-small 'Verdana'; margin-right:1.5em}
  27.       <!-- container for expanding/collapsing content -->
  28.         .c  {cursor:hand}
  29.       <!-- button - contains +/-/nbsp -->
  30.         .b  {color:red; font-family:'Courier New'; font-weight:bold; text-decoration:none}
  31.       <!-- element container -->
  32.         .e  {margin-left:1em; text-indent:-1em; margin-right:1em}
  33.       <!-- comment or cdata -->
  34.         .k  {margin-left:1em; text-indent:-1em; margin-right:1em}
  35.       <!-- tag -->
  36.         .t  {color:#990000}
  37.       <!-- tag in xsl namespace -->
  38.         .xt {color:#990099}
  39.       <!-- attribute in xml or xmlns namespace -->
  40.         .ns {color:red}
  41.       <!-- attribute in dt namespace -->
  42.         .dt {color:green}
  43.       <!-- markup characters -->
  44.         .m  {color:blue}
  45.       <!-- text node -->
  46.         .tx {font-weight:bold}
  47.       <!-- multi-line (block) cdata -->
  48.         .db {text-indent:0px; margin-left:1em; margin-top:0px; margin-bottom:0px;
  49.              padding-left:.3em; border-left:1px solid #CCCCCC; font:small Courier}
  50.       <!-- single-line (inline) cdata -->
  51.         .di {font:small Courier}
  52.       <!-- DOCTYPE declaration -->
  53.         .d  {color:blue}
  54.       <!-- pi -->
  55.         .pi {color:blue}
  56.       <!-- multi-line (block) comment -->
  57.         .cb {text-indent:0px; margin-left:1em; margin-top:0px; margin-bottom:0px;
  58.              padding-left:.3em; font:small Courier; color:#888888}
  59.       <!-- single-line (inline) comment -->
  60.         .ci {font:small Courier; color:#888888}
  61.         PRE {margin:0px; display:inline}
  62.       </STYLE>
  63.  
  64.       <SCRIPT><xsl:comment><![CDATA[
  65.         // Detect and switch the display of CDATA and comments from an inline view
  66.         //  to a block view if the comment or CDATA is multi-line.
  67.         function f(e)
  68.         {
  69.           // if this element is an inline comment, and contains more than a single
  70.           //  line, turn it into a block comment.
  71.           if (e.className == "ci") {
  72.             if (e.children(0).innerText.indexOf("\n") > 0)
  73.               fix(e, "cb");
  74.           }
  75.           
  76.           // if this element is an inline cdata, and contains more than a single
  77.           //  line, turn it into a block cdata.
  78.           if (e.className == "di") {
  79.             if (e.children(0).innerText.indexOf("\n") > 0)
  80.               fix(e, "db");
  81.           }
  82.           
  83.           // remove the id since we only used it for cleanup
  84.           e.id = "";
  85.         }
  86.         
  87.         // Fix up the element as a "block" display and enable expand/collapse on it
  88.         function fix(e, cl)
  89.         {
  90.           // change the class name and display value
  91.           e.className = cl;
  92.           e.style.display = "block";
  93.           
  94.           // mark the comment or cdata display as a expandable container
  95.           j = e.parentElement.children(0);
  96.           j.className = "c";
  97.  
  98.           // find the +/- symbol and make it visible - the dummy link enables tabbing
  99.           k = j.children(0);
  100.           k.style.visibility = "visible";
  101.           k.href = "#";
  102.         }
  103.  
  104.         // Change the +/- symbol and hide the children.  This function works on "element"
  105.         //  displays
  106.         function ch(e)
  107.         {
  108.           // find the +/- symbol
  109.           mark = e.children(0).children(0);
  110.           
  111.           // if it is already collapsed, expand it by showing the children
  112.           if (mark.innerText == "+")
  113.           {
  114.             mark.innerText = "-";
  115.             for (var i = 1; i < e.children.length; i++)
  116.               e.children(i).style.display = "block";
  117.           }
  118.           
  119.           // if it is expanded, collapse it by hiding the children
  120.           else if (mark.innerText == "-")
  121.           {
  122.             mark.innerText = "+";
  123.             for (var i = 1; i < e.children.length; i++)
  124.               e.children(i).style.display="none";
  125.           }
  126.         }
  127.         
  128.         // Change the +/- symbol and hide the children.  This function work on "comment"
  129.         //  and "cdata" displays
  130.         function ch2(e)
  131.         {
  132.           // find the +/- symbol, and the "PRE" element that contains the content
  133.           mark = e.children(0).children(0);
  134.           contents = e.children(1);
  135.           
  136.           // if it is already collapsed, expand it by showing the children
  137.           if (mark.innerText == "+")
  138.           {
  139.             mark.innerText = "-";
  140.             // restore the correct "block"/"inline" display type to the PRE
  141.             if (contents.className == "db" || contents.className == "cb")
  142.               contents.style.display = "block";
  143.             else contents.style.display = "inline";
  144.           }
  145.           
  146.           // if it is expanded, collapse it by hiding the children
  147.           else if (mark.innerText == "-")
  148.           {
  149.             mark.innerText = "+";
  150.             contents.style.display = "none";
  151.           }
  152.         }
  153.         
  154.         // Handle a mouse click
  155.         function cl()
  156.         {
  157.           e = window.event.srcElement;
  158.           
  159.           // make sure we are handling clicks upon expandable container elements
  160.           if (e.className != "c")
  161.           {
  162.             e = e.parentElement;
  163.             if (e.className != "c")
  164.             {
  165.               return;
  166.             }
  167.           }
  168.           e = e.parentElement;
  169.           
  170.           // call the correct funtion to change the collapse/expand state and display
  171.           if (e.className == "e")
  172.             ch(e);
  173.           if (e.className == "k")
  174.             ch2(e);
  175.         }
  176.  
  177.         // Dummy function for expand/collapse link navigation - trap onclick events instead
  178.         function ex() 
  179.         {}
  180.  
  181.         // Erase bogus link info from the status window
  182.         function h()
  183.         {
  184.           window.status=" ";
  185.         }
  186.  
  187.         // Set the onclick handler
  188.         document.onclick = cl;
  189.         
  190.       ]]></xsl:comment></SCRIPT>
  191.     </HEAD>
  192.  
  193.     <BODY class="st"><xsl:apply-templates/></BODY>
  194.  
  195.   </HTML>
  196. </xsl:template>
  197.  
  198. <!-- Templates for each node type follows.  The output of each template has a similar structure
  199.   to enable script to walk the result tree easily for handling user interaction. -->
  200.   
  201. <!-- Template for the DOCTYPE declaration.  No way to get the DOCTYPE, so we just put in a placeholder -->
  202. <xsl:template match="node()[nodeType()=10]">
  203.   <DIV class="e"><SPAN>
  204.   <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN>
  205.   <SPAN class="d"><!DOCTYPE <xsl:node-name/><I> (View Source for full doctype...)</I>></SPAN>
  206.   </SPAN></DIV>
  207. </xsl:template>
  208.  
  209. <!-- Template for pis not handled elsewhere -->
  210. <xsl:template match="pi()">
  211.   <DIV class="e">
  212.   <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN>
  213.   <SPAN class="m"><?</SPAN><SPAN class="pi"><xsl:node-name/> <xsl:value-of/></SPAN><SPAN class="m">?></SPAN>
  214.   </DIV>
  215. </xsl:template>
  216.  
  217. <!-- Template for the XML declaration.  Need a separate template because the pseudo-attributes
  218.     are actually exposed as attributes instead of just element content, as in other pis -->
  219. <xsl:template match="pi('xml')">
  220.   <DIV class="e">
  221.   <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN>
  222.   <SPAN class="m"><?</SPAN><SPAN class="pi">xml <xsl:for-each select="@*"><xsl:node-name/>="<xsl:value-of/>" </xsl:for-each></SPAN><SPAN class="m">?></SPAN>
  223.   </DIV>
  224. </xsl:template>
  225.  
  226. <!-- Template for attributes not handled elsewhere -->
  227. <xsl:template match="@*" xml:space="preserve"><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*/@*">x</xsl:if>t</xsl:attribute> <xsl:node-name/></SPAN><SPAN class="m">="</SPAN><B><xsl:value-of/></B><SPAN class="m">"</SPAN></xsl:template>
  228.  
  229. <!-- Template for attributes in the xmlns or xml namespace -->
  230. <xsl:template match="@xmlns:*|@xmlns|@xml:*"><SPAN class="ns"> <xsl:node-name/></SPAN><SPAN class="m">="</SPAN><B class="ns"><xsl:value-of/></B><SPAN class="m">"</SPAN></xsl:template>
  231.  
  232. <!-- Template for attributes in the dt namespace -->
  233. <xsl:template match="@dt:*|@d2:*"><SPAN class="dt"> <xsl:node-name/></SPAN><SPAN class="m">="</SPAN><B class="dt"><xsl:value-of/></B><SPAN class="m">"</SPAN></xsl:template>
  234.  
  235. <!-- Template for text nodes -->
  236. <xsl:template match="textNode()">
  237.   <DIV class="e">
  238.   <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN>
  239.   <SPAN class="tx"><xsl:value-of/></SPAN>
  240.   </DIV>
  241. </xsl:template>
  242.  
  243.  
  244. <!-- Note that in the following templates for comments and cdata, by default we apply a style
  245.   appropriate for single line content (e.g. non-expandable, single line display).  But we also
  246.   inject the attribute 'id="clean"' and a script call 'f(clean)'.  As the output is read by the
  247.   browser, it executes the function immediately.  The function checks to see if the comment or
  248.   cdata has multi-line data, in which case it changes the style to a expandable, multi-line
  249.   display.  Performing this switch in the DHTML instead of from script in the XSL increases
  250.   the performance of the style sheet, especially in the browser's asynchronous case -->
  251.   
  252. <!-- Template for comment nodes -->
  253. <xsl:template match="comment()">
  254.   <DIV class="k">
  255.   <SPAN><A class="b" onclick="return false" onfocus="h()" STYLE="visibility:hidden">-</A> <SPAN class="m"><!--</SPAN></SPAN>
  256.   <SPAN id="clean" class="ci"><PRE><xsl:value-of/></PRE></SPAN>
  257.   <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN> <SPAN class="m">--></SPAN>
  258.   <SCRIPT>f(clean);</SCRIPT></DIV>
  259. </xsl:template>
  260.  
  261. <!-- Template for cdata nodes -->
  262. <xsl:template match="cdata()">
  263.   <DIV class="k">
  264.   <SPAN><A class="b" onclick="return false" onfocus="h()" STYLE="visibility:hidden">-</A> <SPAN class="m"><![CDATA[</SPAN></SPAN>
  265.   <SPAN id="clean" class="di"><PRE><xsl:value-of/></PRE></SPAN>
  266.   <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN> <SPAN class="m">]]></SPAN>
  267.   <SCRIPT>f(clean);</SCRIPT></DIV>
  268. </xsl:template>
  269.  
  270.  
  271. <!-- Note the following templates for elements may examine children.  This harms to some extent
  272.   the ability to process a document asynchronously - we can't process an element until we have
  273.   read and examined at least some of its children.  Specifically, the first element child must
  274.   be read before any template can be chosen.  And any element that does not have element
  275.   children must be read completely before the correct template can be chosen. This seems 
  276.   an acceptable performance loss in the light of the formatting possibilities available 
  277.   when examining children. -->
  278.  
  279. <!-- Template for elements not handled elsewhere (leaf nodes) -->
  280. <xsl:template match="*">
  281.   <DIV class="e"><DIV STYLE="margin-left:1em;text-indent:-2em">
  282.   <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN>
  283.   <SPAN class="m"><</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN> <xsl:apply-templates select="@*"/><SPAN class="m"> /></SPAN>
  284.   </DIV></DIV>
  285. </xsl:template>
  286.   
  287. <!-- Template for elements with comment, pi and/or cdata children -->
  288. <xsl:template match="*[node()]">
  289.   <DIV class="e">
  290.   <DIV class="c"><A href="#" onclick="return false" onfocus="h()" class="b">-</A> <SPAN class="m"><</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN><xsl:apply-templates select="@*"/> <SPAN class="m">></SPAN></DIV>
  291.   <DIV><xsl:apply-templates/>
  292.   <DIV><SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN> <SPAN class="m"></</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN><SPAN class="m">></SPAN></DIV>
  293.   </DIV></DIV>
  294. </xsl:template>
  295.  
  296. <!-- Template for elements with only text children -->
  297. <xsl:template match="*[textNode()$and$$not$(comment()$or$pi()$or$cdata())]">
  298.   <DIV class="e"><DIV STYLE="margin-left:1em;text-indent:-2em">
  299.   <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN> <SPAN class="m"><</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN><xsl:apply-templates select="@*"/>
  300.   <SPAN class="m">></SPAN><SPAN class="tx"><xsl:value-of/></SPAN><SPAN class="m"></</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN><SPAN class="m">></SPAN>
  301.   </DIV></DIV>
  302. </xsl:template>
  303.  
  304. <!-- Template for elements with element children -->
  305. <xsl:template match="*[*]">
  306.   <DIV class="e">
  307.   <DIV class="c" STYLE="margin-left:1em;text-indent:-2em"><A href="#" onclick="return false" onfocus="h()" class="b">-</A> <SPAN class="m"><</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN><xsl:apply-templates select="@*"/> <SPAN class="m">></SPAN></DIV>
  308.   <DIV><xsl:apply-templates/>
  309.   <DIV><SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN> <SPAN class="m"></</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN><SPAN class="m">></SPAN></DIV>
  310.   </DIV></DIV>
  311. </xsl:template>
  312.  
  313. </xsl:stylesheet>